<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>设计模式 - 工厂模式（`Factory Pattern`） | 爪哇干货分享</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/favicon.ico">
    <script charset="utf-8" async="async" src="/js/jquery.min.js"></script>
    <script charset="utf-8" async="async" src="/js/global.js"></script>
    <script charset="utf-8" async="async" src="/js/fingerprint2.min.js"></script>
    <script charset="utf-8" async="async" src="https://s9.cnzz.com/z_stat.php?id=1278232949&amp;web_id=1278232949"></script>
    <script>
              var _hmt = _hmt || [];
              (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?e68b39347be2339192f80082c317901e";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
              })();
            </script>
    <meta name="description" content="包含: Java 基础，面试小册，Spring源码解析，中间件原理">
    <meta property="article:modified_time" content="2022-03-30T11:44:00.000Z">
    <meta property="og:title" content="设计模式 - 工厂模式（Factory Pattern）">
    <meta property="og:type" content="article">
    <meta property="og:url" content="/md/dev-spec/pattern/3_factory.html">
    <meta name="twitter:title" content="设计模式 - 工厂模式（Factory Pattern）">
    <meta name="twitter:url" content="/md/dev-spec/pattern/3_factory.html">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="robots" content="all">
    <meta name="author" content="janker">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="keywords" content="爪哇干货分享,  中间件, Spring, Java基础, 面试小册">
    <meta name="apple-mobile-web-app-capable" content="yes">
    
    <link rel="preload" href="/assets/css/0.styles.b854e512.css" as="style"><link rel="preload" href="/assets/css/styles.css?v=1648640762568" as="style"><link rel="preload" href="/assets/js/cg-styles.js?v=1648640762568" as="script"><link rel="preload" href="/assets/js/cg-app.js?v=1648640762568" as="script"><link rel="preload" href="/assets/js/cg-4.js?v=1648640762568" as="script"><link rel="preload" href="/assets/js/cg-3.js?v=1648640762568" as="script"><link rel="preload" href="/assets/js/cg-20.js?v=1648640762568" as="script"><link rel="preload" href="/assets/js/cg-5.js?v=1648640762568" as="script"><link rel="preload" href="/assets/js/cg-6.js?v=1648640762568" as="script">
    <link rel="stylesheet" href="/assets/css/0.styles.b854e512.css"><link rel="stylesheet" href="/assets/css/styles.css?v=1648640762568">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">爪哇干货分享</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java" class="dropdown-title"><span class="title">Java</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/java/interview/book.html" class="nav-link">
  面经手册
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="方法" class="dropdown-title"><span class="title">方法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/dev-spec/pattern/1_overview.html" class="nav-link">
  设计模式
</a></li></ul></div></div><div class="nav-item"><a href="/md/about/me/about-me.html" class="nav-link">
  关于
</a></div><div class="nav-item"><a href="https://github.com/janker0718/ShareJava" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java" class="dropdown-title"><span class="title">Java</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/java/interview/book.html" class="nav-link">
  面经手册
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="方法" class="dropdown-title"><span class="title">方法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/dev-spec/pattern/1_overview.html" class="nav-link">
  设计模式
</a></li></ul></div></div><div class="nav-item"><a href="/md/about/me/about-me.html" class="nav-link">
  关于
</a></div><div class="nav-item"><a href="https://github.com/janker0718/ShareJava" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>设计模式</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/dev-spec/pattern/1_overview.html" class="sidebar-link">设计模式 - 概述</a></li><li><a href="/md/dev-spec/pattern/2_singleton.html" class="sidebar-link">设计模式 - 单例模式（Singleton Pattern）</a></li><li><a href="/md/dev-spec/pattern/3_factory.html" aria-current="page" class="active sidebar-link">设计模式 - 工厂模式（Factory Pattern）</a></li><li><a href="/md/dev-spec/pattern/4_abstract-factory.html" class="sidebar-link">设计模式 - 抽象工厂模式（Abstract Factory Pattern）</a></li></ul></section></li></ul> </aside> <div><main class="page"> <div class="theme-default-content content__default"><h1 id="设计模式-工厂模式-factory-pattern"><a href="#设计模式-工厂模式-factory-pattern" class="header-anchor">#</a> 设计模式 - 工厂模式（<code>Factory Pattern</code>）</h1> <p></p><div class="table-of-contents"><ul><li><a href="#概述">概述</a><ul><li><a href="#意图">意图</a></li><li><a href="#解决的问题点">解决的问题点</a></li><li><a href="#关键思路">关键思路</a></li><li><a href="#优缺点">优缺点</a></li><li><a href="#使用场景">使用场景</a></li></ul></li><li><a href="#实现">实现</a><ul><li><a href="#_1-创建接口">1. 创建接口</a></li><li><a href="#_2-创建多个接口实现类">2.  创建多个接口实现类</a></li><li><a href="#_3-创建一个工厂-生成基于给定信息的实体类的对象。">3. 创建一个工厂，生成基于给定信息的实体类的对象。</a></li><li><a href="#_4-使用该工厂-通过传递类型信息来获取实体类的对象。">4. 使用该工厂，通过传递类型信息来获取实体类的对象。</a></li><li><a href="#_5-执行程序-输出结果">5. 执行程序，输出结果：</a></li></ul></li></ul></div><p></p> <blockquote><p>工厂模式（Factory Pattern）是 Java 中最常用的设计模式之一。这种类型的设计模式属于创建型模式，它提供了一种创建对象的最佳方式。
在工厂模式中，我们在创建对象时不会对客户端暴露创建逻辑，并且是通过使用一个共同的接口来指向新创建的对象。</p></blockquote> <h2 id="概述"><a href="#概述" class="header-anchor">#</a> 概述</h2> <h3 id="意图"><a href="#意图" class="header-anchor">#</a> 意图</h3> <p>定义一个创建对象的接口，让其子类自己决定实例化哪一个工厂类，工厂模式使其创建过程延迟到子类进行。</p> <h3 id="解决的问题点"><a href="#解决的问题点" class="header-anchor">#</a> 解决的问题点</h3> <p>主要解决接口选择的问题。</p> <p>我们明确地计划不同条件下创建不同实例时。</p> <p>让其子类实现工厂接口，返回的也是一个抽象的产品。</p> <h3 id="关键思路"><a href="#关键思路" class="header-anchor">#</a> 关键思路</h3> <p>创建过程在其子类执行。</p> <h3 id="优缺点"><a href="#优缺点" class="header-anchor">#</a> 优缺点</h3> <p><strong>优点</strong></p> <ol><li>一个调用者想创建一个对象，只要知道其名称就可以了。</li> <li>扩展性高，如果想增加一个产品，只要扩展一个工厂类就可以。</li> <li>屏蔽产品的具体实现，调用者只关心产品的接口。</li></ol> <p><strong>缺点</strong></p> <p>每次增加一个产品时，都需要增加一个具体类和对象实现工厂，使得系统中类的个数成倍增加，在一定程度上增加了系统的复杂度，同时也增加了系统具体类的依赖。这并不是什么好事。</p> <h3 id="使用场景"><a href="#使用场景" class="header-anchor">#</a> 使用场景</h3> <ol><li>日志记录器：记录可能记录到本地硬盘、系统事件、远程服务器等，用户可以选择记录日志到什么地方。</li> <li>数据库访问，当用户不知道最后系统采用哪一类数据库，以及数据库可能有变化时。</li> <li>设计一个连接服务器的框架，需要三个协议，&quot;<code>POP3</code>&quot;、&quot;<code>IMAP</code>&quot;、&quot;<code>HTTP</code>&quot;，可以把这三个作为产品类，共同实现一个接口。</li></ol> <div class="custom-block warning"><p class="custom-block-title">注意</p> <p>作为一种创建类模式，在任何需要生成复杂对象的地方，都可以使用工厂方法模式。有一点需要注意的地方就是复杂对象适合使用工厂模式，而简单对象，特别是只需要通过 <code>new</code> 就可以完成创建的对象，无需使用工厂模式。如果使用工厂模式，就需要引入一个工厂类，会增加系统的复杂度。</p></div> <h2 id="实现"><a href="#实现" class="header-anchor">#</a> 实现</h2> <p>我们将创建一个 <code>Shape</code> 接口和实现 <code>Shape</code> 接口的实体类。下一步是定义工厂类 <code>ShapeFactory</code>。</p> <p><code>FactoryPatternDemo</code> 类使用 <code>ShapeFactory</code> 来获取 <code>Shape</code> 对象。它将向 <code>ShapeFactory</code> 传递信息（<code>CIRCLE</code> / <code>RECTANGLE</code> / <code>SQUARE</code>），以便获取它所需对象的类型。</p> <p><img alt="" data-src="https://cdn.jsdelivr.net/gh/janker0718/image_store@master/img/20220330102931.png" loading="lazy" class="lazy"></p> <h3 id="_1-创建接口"><a href="#_1-创建接口" class="header-anchor">#</a> 1. 创建接口</h3> <div class="language-java line-numbers-mode"><pre class="language-java"><code>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">Shape</span> <span class="token punctuation">{</span>
   <span class="token keyword">void</span> <span class="token function">draw</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="_2-创建多个接口实现类"><a href="#_2-创建多个接口实现类" class="header-anchor">#</a> 2.  创建多个接口实现类</h3> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Rectangle</span> <span class="token keyword">implements</span> <span class="token class-name">Shape</span> <span class="token punctuation">{</span>
 
   <span class="token annotation punctuation">@Override</span>
   <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">draw</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;Inside Rectangle::draw() method.&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Square</span> <span class="token keyword">implements</span> <span class="token class-name">Shape</span> <span class="token punctuation">{</span>
 
   <span class="token annotation punctuation">@Override</span>
   <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">draw</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;Inside Square::draw() method.&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Circle</span> <span class="token keyword">implements</span> <span class="token class-name">Shape</span> <span class="token punctuation">{</span>
 
   <span class="token annotation punctuation">@Override</span>
   <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">draw</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;Inside Circle::draw() method.&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h3 id="_3-创建一个工厂-生成基于给定信息的实体类的对象。"><a href="#_3-创建一个工厂-生成基于给定信息的实体类的对象。" class="header-anchor">#</a> 3. 创建一个工厂，生成基于给定信息的实体类的对象。</h3> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ShapeFactory</span> <span class="token punctuation">{</span>
    
   <span class="token comment">//使用 getShape 方法获取形状类型的对象</span>
   <span class="token keyword">public</span> <span class="token class-name">Shape</span> <span class="token function">getShape</span><span class="token punctuation">(</span><span class="token class-name">String</span> shapeType<span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token keyword">if</span><span class="token punctuation">(</span>shapeType <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
         <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>        
      <span class="token keyword">if</span><span class="token punctuation">(</span>shapeType<span class="token punctuation">.</span><span class="token function">equalsIgnoreCase</span><span class="token punctuation">(</span><span class="token string">&quot;CIRCLE&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
         <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Circle</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>shapeType<span class="token punctuation">.</span><span class="token function">equalsIgnoreCase</span><span class="token punctuation">(</span><span class="token string">&quot;RECTANGLE&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
         <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Rectangle</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>shapeType<span class="token punctuation">.</span><span class="token function">equalsIgnoreCase</span><span class="token punctuation">(</span><span class="token string">&quot;SQUARE&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
         <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Square</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
      <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
   <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><h3 id="_4-使用该工厂-通过传递类型信息来获取实体类的对象。"><a href="#_4-使用该工厂-通过传递类型信息来获取实体类的对象。" class="header-anchor">#</a> 4. 使用该工厂，通过传递类型信息来获取实体类的对象。</h3> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">FactoryPatternDemo</span> <span class="token punctuation">{</span>
 
   <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token class-name">ShapeFactory</span> shapeFactory <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ShapeFactory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 
      <span class="token comment">//获取 Circle 的对象，并调用它的 draw 方法</span>
      <span class="token class-name">Shape</span> shape1 <span class="token operator">=</span> shapeFactory<span class="token punctuation">.</span><span class="token function">getShape</span><span class="token punctuation">(</span><span class="token string">&quot;CIRCLE&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 
      <span class="token comment">//调用 Circle 的 draw 方法</span>
      shape1<span class="token punctuation">.</span><span class="token function">draw</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 
      <span class="token comment">//获取 Rectangle 的对象，并调用它的 draw 方法</span>
      <span class="token class-name">Shape</span> shape2 <span class="token operator">=</span> shapeFactory<span class="token punctuation">.</span><span class="token function">getShape</span><span class="token punctuation">(</span><span class="token string">&quot;RECTANGLE&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 
      <span class="token comment">//调用 Rectangle 的 draw 方法</span>
      shape2<span class="token punctuation">.</span><span class="token function">draw</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 
      <span class="token comment">//获取 Square 的对象，并调用它的 draw 方法</span>
      <span class="token class-name">Shape</span> shape3 <span class="token operator">=</span> shapeFactory<span class="token punctuation">.</span><span class="token function">getShape</span><span class="token punctuation">(</span><span class="token string">&quot;SQUARE&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 
      <span class="token comment">//调用 Square 的 draw 方法</span>
      shape3<span class="token punctuation">.</span><span class="token function">draw</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><h3 id="_5-执行程序-输出结果"><a href="#_5-执行程序-输出结果" class="header-anchor">#</a> 5. 执行程序，输出结果：</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>Inside Circle::draw<span class="token punctuation">(</span><span class="token punctuation">)</span> method.
Inside Rectangle::draw<span class="token punctuation">(</span><span class="token punctuation">)</span> method.
Inside Square::draw<span class="token punctuation">(</span><span class="token punctuation">)</span> method.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/janker0718/ShareJava/edit/master/docs/md/dev-spec/pattern/3_factory.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">3/30/2022,</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/md/dev-spec/pattern/2_singleton.html" class="prev">
          设计模式 - 单例模式（Singleton Pattern）
        </a></span> <span class="next"><a href="/md/dev-spec/pattern/4_abstract-factory.html">
          设计模式 - 抽象工厂模式（Abstract Factory Pattern）
        </a>
        →
      </span></p></div> </main></div> <aside class="page-sidebar"> <div class="page-side-toolbar"><div class="option-box-toc-fixed"><div class="toc-container-sidebar"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:650px"><div style="font-weight:bold;text-align:center;">设计模式 - 工厂模式（Factory Pattern）</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/dev-spec/pattern/3_factory.html#概述" class="toc-sidebar-link">概述</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#意图" class="toc-sidebar-link">意图</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#解决的问题点" class="toc-sidebar-link">解决的问题点</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#关键思路" class="toc-sidebar-link">关键思路</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#优缺点" class="toc-sidebar-link">优缺点</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#使用场景" class="toc-sidebar-link">使用场景</a></li></ul></li><li><a href="/md/dev-spec/pattern/3_factory.html#实现" class="toc-sidebar-link">实现</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_1-创建接口" class="toc-sidebar-link">1. 创建接口</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_2-创建多个接口实现类" class="toc-sidebar-link">2.  创建多个接口实现类</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_3-创建一个工厂-生成基于给定信息的实体类的对象。" class="toc-sidebar-link">3. 创建一个工厂，生成基于给定信息的实体类的对象。</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_4-使用该工厂-通过传递类型信息来获取实体类的对象。" class="toc-sidebar-link">4. 使用该工厂，通过传递类型信息来获取实体类的对象。</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_5-执行程序-输出结果" class="toc-sidebar-link">5. 执行程序，输出结果：</a></li></ul></li></ul></div></div></div></div></div> <div class="option-box"><a title="点击切换全屏" style="text-align:center;padding-left:2px;"><img src="/images/system/full.png" width="30px" class="nozoom"> <span style="color:gray;font-size:11px;font-weight:400;">全屏看</span></a></div> <div class="option-box-toc-over"><img src="/images/system/mulu.png" class="nozoom"> <span class="show-txt">目录</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:550px"><div style="font-weight:bold;text-align:center;">设计模式 - 工厂模式（Factory Pattern）</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/dev-spec/pattern/3_factory.html#概述" class="toc-sidebar-link">概述</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#意图" class="toc-sidebar-link">意图</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#解决的问题点" class="toc-sidebar-link">解决的问题点</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#关键思路" class="toc-sidebar-link">关键思路</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#优缺点" class="toc-sidebar-link">优缺点</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#使用场景" class="toc-sidebar-link">使用场景</a></li></ul></li><li><a href="/md/dev-spec/pattern/3_factory.html#实现" class="toc-sidebar-link">实现</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_1-创建接口" class="toc-sidebar-link">1. 创建接口</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_2-创建多个接口实现类" class="toc-sidebar-link">2.  创建多个接口实现类</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_3-创建一个工厂-生成基于给定信息的实体类的对象。" class="toc-sidebar-link">3. 创建一个工厂，生成基于给定信息的实体类的对象。</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_4-使用该工厂-通过传递类型信息来获取实体类的对象。" class="toc-sidebar-link">4. 使用该工厂，通过传递类型信息来获取实体类的对象。</a></li><li class="toc-sidebar-sub-header"><a href="/md/dev-spec/pattern/3_factory.html#_5-执行程序-输出结果" class="toc-sidebar-link">5. 执行程序，输出结果：</a></li></ul></li></ul></div></div></div></div></div> <div class="option-box"><img src="/images/system/wechat.png" class="nozoom"> <span class="show-txt">手机看</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.9rem">微信扫一扫</span> <img height="180px" src="https://api.qrserver.com/v1/create-qr-code/?data=https://www.share-java.com/md/dev-spec/pattern/3_factory.html" style="margin:10px;">
                可以<b>手机看</b>或分享至<b>朋友圈</b></div></div></div></div> <div class="option-box"><img src="/images/system/toggle.png" width="30px" class="nozoom"> <span class="show-txt">左栏</span></div> <div class="option-box"><img src="/images/system/download-2.png" width="25px" class="nozoom"> <span class="show-txt">下资料</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">扫描公众号，回复<span style="color:red;">“66”</span>下载<span style="color:red;">1TB+</span>学习技术资料、PDF书籍、简历模板「无任何套路」</span> <img src="https://cdn.jsdelivr.net/gh/janker0718/image_store/img/20220103214503494.png" height="180px" style="margin:10px;"> <b>公众号:</b> 爪哇干货分享
              </div></div></div></div> <div title="设计模式 - 单例模式（Singleton Pattern）" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/dev-spec/pattern/2_singleton.html"><img src="/images/system/pre2.png" width="30px" class="nozoom"> <span class="show-txt">上一篇</span></a></div> <div title="设计模式 - 抽象工厂模式（Abstract Factory Pattern）" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/dev-spec/pattern/4_abstract-factory.html"><img src="/images/system/next2.png" width="30px" class="nozoom"> <span class="show-txt">下一篇</span></a></div></div>  <div class="page-side-sitemap"><div class="option-box"><img src="/images/system/sitemap.png" class="nozoom img"> <span class="show-txt">站点图</span> <div class="sitemap-container"><h4>站点导航图
              <a href="/md/about/me/about-me.html" class="sitemap-top-link"> 关于我</a> <a href="/md/about/me/about-arch.html" class="sitemap-top-link"> 关于学习</a></h4> <table class="sitemap-table"><tr><td nowrap="nowrap"><div class="sitemap-col-group">常用搜索</div></td> <td><div class="sitemap-col-item"><a href="http://www.baidu.com/" target="_blank" title="百度">  
          百度
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="http://www.google.com/" target="_blank" title="Google">  
          Google
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="http://www.bing.com/" target="_blank" title="Bing">  
          Bing
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://github.com" target="_blank" title="Github">  
          Github
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.programcreek.com/java-api-examples/index.php" target="_blank" title="搜代码">  
          搜代码
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div></td> <!----></tr><tr><td nowrap="nowrap"><div class="sitemap-col-group">技术社区</div></td> <td><div class="sitemap-col-item"><a href="http://www.csdn.net/" target="_blank" title="CDSN">  
          CDSN
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="http://www.cnblogs.com/" target="_blank" title="博客园">  
          博客园
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.oschina.net" target="_blank" title="OSChina">  
          OSChina
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://segmentfault.com/" target="_blank" title="思否">  
          思否
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://juejin.im" target="_blank" title="掘金">  
          掘金
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.linuxidc.com/" target="_blank" title="Linux公社">  
          Linux公社
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.ibm.com/developerworks/cn/" target="_blank" title="IBM 开发者">  
          IBM 开发者
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://stackoverflow.com" target="_blank" title="StackOverflow">  
          StackOverflow
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div></td> <!----></tr></table></div></div></div> <!----> </aside></div><div class="global-ui"><div class="read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="read-more-btn" target="_self" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">阅读全文</a> <div id="btw-modal-wrap" style="display: none;"><div id="btw-mask" style="position: fixed; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.7; z-index: 999; background: rgb(0, 0, 0);"></div> <div id="btw-modal" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 300px; text-align: center; font-size: 13px; background: rgb(255, 255, 255); border-radius: 10px; z-index: 9999; font-family: PingFangSC-Regular, sans-serif;"><span id="btw-modal-close-btn" style="position: absolute; top: 5px; right: 15px; line-height: 34px; font-size: 34px; cursor: pointer; opacity: 0.2; z-index: 9999; color: rgb(0, 0, 0); background: none; border: none; outline: none;">×</span> <p id="btw-modal-header" style="margin-top: 40px; line-height: 1.8; font-size: 13px;">
                扫码或搜索：<span style="color: #E9405A; font-weight: bold;">爪哇干货分享</span> <br>发送：<span id="fustack-token" class="token" style="color: #e9415a; font-weight: bold; font-size: 17px; margin-bottom: 45px;">10086</span> <br>即可<span style="color: #e9415a; font-weight: bold;">立即永久</span>解锁本站全部文章</p> <img src="/images/personal/qrcode.png" style="width: 180px; margin-top: 10px; margin-bottom: 30px; border: 8px solid rgb(230, 230, 230);"></div></div></div><div class="pay-read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="pay-read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="pay-read-more-btn" target="_blank" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">付费阅读</a></div><!----><div></div></div></div>
    <script src="/assets/js/cg-styles.js?v=1648640762568" defer></script><script src="/assets/js/cg-4.js?v=1648640762568" defer></script><script src="/assets/js/cg-3.js?v=1648640762568" defer></script><script src="/assets/js/cg-20.js?v=1648640762568" defer></script><script src="/assets/js/cg-5.js?v=1648640762568" defer></script><script src="/assets/js/cg-6.js?v=1648640762568" defer></script><script src="/assets/js/cg-app.js?v=1648640762568" defer></script>
  </body>
</html>
